/**
 * 
 */
package com.cipe.cmrs.controllers.payment;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.cipe.cmrs.bean.PaymentRequestBean;

/**
 * @author Incepio
 * 
 */
@Controller
@RequestMapping("/secure/showEditPaymentrequest.do")
public class EditPaymentRequestController extends AbstractPaymentController {
    /**
	 * 
	 */
    private static final long serialVersionUID = 3480388481687538109L;

    private static final String FORM_VIEW = "payment/editPaymentrequest";

    public EditPaymentRequestController() {
        setFormView(FORM_VIEW);
        setSuccessView(FORM_VIEW);
    }

    @ModelAttribute(COMMAND_NAME)
    public PaymentRequestBean getCommand(@RequestParam Integer id) {
        return paymentrequestService.getPaymentRequestbean(id);
    }

    protected Map<String, Object> getReferenceData(PaymentRequestBean bean, HttpServletRequest request) {
        Map<String, Object> map = super.getReferenceData(bean, request);
        map.put("createdByCurrentUser", bean.getCreatedBy() == null || getUserId(request) == bean.getCreatedById());
        // By Andy: UAT-040 - Editing Payment Request - Payment Request can only
        // be edited IF status is "New" or "Rejected"
        boolean canEdit = getText("status.payment.process.new").equals(bean.getStatusCode())
            || getText("status.payment.process.rejected").equals(bean.getStatusCode());
        map.put("canEdit", canEdit);
        return map;
    }

}
